from sqlalchemy import BigInteger
from sqlalchemy.orm import Mapped, mapped_column, relationship

from .base import TimedBaseModel


class User(TimedBaseModel):
    __tablename__ = "user"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    telegram_id: Mapped[int] = mapped_column(BigInteger, unique=True)
    username: Mapped[str]
    phone_number: Mapped[str]
    bills = relationship("Bill", back_populates="user", cascade="all, delete")

    def __repr__(self):
        return f"<Пользователь №{self.id} {self.telegram_id}>"

    def __str__(self):
        return self.__repr__()
